package top.eggcode.common.exception;

import top.eggcode.common.mvc.ResultStatus;

/**
 * @author huangxunhui
 * Date: Created in 2018-12-18 10:25
 * Utils: Intellij Idea
 * Description: 设计异常（系统通用异常）
 */
public class ApplicationException extends RuntimeException {

    /**
     * 状态码
     */
    private final Integer code;

    /**
     * 事发地
     */
    private final String location;

    public ApplicationException(String message) {
        super(message);
        this.code = 0;
        this.location = "";

    }

    public ApplicationException(String message, String location) {
        super(message);
        this.code = 0;
        this.location = location;

    }

    public ApplicationException(String message, Throwable cause) {
        super(message, cause);
        this.code = 0;
        this.location = "";

    }

    public ApplicationException(Throwable cause, String message) {
        super(message, cause);
        this.code = 0;
        this.location = "";

    }

    public ApplicationException(ResultStatus resultStatus, Throwable cause) {
        super(resultStatus.getMsg(), cause);
        this.code = 0;
        this.location = "";

    }

    /**
     * 构造
     *
     * @param resultStatus 返回枚举对象
     * @param message      描述
     * @param location     事发地
     */
    public ApplicationException(ResultStatus resultStatus, String message, String location) {
        super(message);
        this.code = resultStatus.getCode();

        this.location = location;
    }

    /**
     * 构造
     *
     * @param resultStatus 返回枚举对象
     * @param location     事发地
     */
    public ApplicationException(ResultStatus resultStatus, String location) {
        super(resultStatus.getMsg());
        this.code = resultStatus.getCode();

        this.location = location;
    }

    /**
     * 构造
     *
     * @param resultStatus 返回枚举对象
     */
    public ApplicationException(ResultStatus resultStatus) {
        super(resultStatus.getMsg());
        this.code = resultStatus.getCode();
        this.location = "";
    }

    /**
     * 构造
     *
     * @param code     状态码
     * @param message  描述
     * @param location 事发地
     */
    public ApplicationException(Integer code, String message, String location) {
        super(message);
        this.code = code;
        this.location = location;
    }

    public Integer getCode() {
        return code;
    }

    public String getLocation() {
        return location;
    }

}
